package com.csk.zsk.compents.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.csk.zsk.commons.action.AjaxActionSupport;
import com.csk.zsk.commons.utils.encode.JsonBinder;
import com.csk.zsk.commons.utils.web.struts2.Struts2Utils;
import com.csk.zsk.compents.entity.Picnews;
import com.csk.zsk.compents.service.PicnewsService;
@Controller
@Scope("prototype")
public class PicnewsAction extends AjaxActionSupport {

	
	private static final long serialVersionUID = -4887444742317517716L;
	private static JsonBinder binder = JsonBinder.buildNonDefaultBinder();
	@Autowired
	private PicnewsService picnewsService;
	
	private String id;
	private String type;
	private String length;
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getLength() {
		return length;
	}
	public void setLength(String length) {
		this.length = length;
	}
	
	public PicnewsAction(){
		binder.setDateFormat("yyyy-MM-dd HH:mm:ss");
	}
	
	/**
	 * 获取头条
	 */
	public void getTop1(){
		Picnews news = picnewsService.getTop1();
		String json = binder.toJson(news);
		Struts2Utils.renderJson(json);
	}
	
	/**
	 * 通过ID获取新闻对象
	 */
	public void getNews(){
		Picnews news = picnewsService.getPicnews(id);
		String json = binder.toJson(news);
		Struts2Utils.renderJson(json);
	}
	
	/**
	 * 通过类型获取新闻列表  时间倒序
	 */
	public void getNewsByTypeByTime(){
		List<Picnews> newsList = picnewsService.getPicnewsByTypeTime(type, Integer.parseInt(length));
		String json = binder.toJson(newsList);
		Struts2Utils.renderJson(json);
		
	}
	/**
	 * 获取全部新闻列表  时间倒序
	 */
	public void getNewsByTime(){
		List<Picnews> newsList = picnewsService.getPicnewsByTime(Integer.parseInt(length));
		String json = binder.toJson(newsList);
		Struts2Utils.renderJson(json);
		
	}
	

}
